home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!genesis.demon.co.uk
- From: Lawrence Kirby <fred@genesis.demon.co.uk>
- Newsgroups: comp.lang.c,comp.os.ms-windows.programmer.win32
- Subject: Re: How can I check whether I file exists in a multi-user environment?
- Date: Wed, 03 Apr 96 12:40:22 GMT
- Organization: none
- Message-ID: <828535222snz@genesis.demon.co.uk>
- References: <4jh4tl$t4c_002@chem.uva.nl> <Dp1oM8.Cns@iquest.net> <4jjn1d$clu@solutions.solon.com> <Dp6sqL.Buz@iquest.net>
- Reply-To: fred@genesis.demon.co.uk
- X-NNTP-Posting-Host: genesis.demon.co.uk
- X-Newsreader: Demon Internet Simple News v1.27
- X-Mail2News-Path: genesis.demon.co.uk
-
- In article <Dp6sqL.Buz@iquest.net> dlmiller@iquest.net "Doug Miller" writes:
-
- >seebs@solutions.solon.com (Peter Seebach) wrote:
-
- >>>#include <io.h>
- >>>int file_exists (char *filename) {
- >>> return (access(filename, 0) == 0);
- >>>} /* returns -1 if file exists, 0 if it does not */
- >>
- >>The reason this is a poor solution is that it doesn't test for existance,
- >>it tests for accessibility.
- >
- >You should check your facts more carefully. You evidently are unfamiliar with
- > the behavior of
- >access( ). It is defined thusly:
- >
- >#include <io.h>
- >int access (const char *filename, int amode);
- >
- >permissible values for amode are:
- > 06 check for read and write permission
- > 04 check for read permission
- > 02 check for write permission
- > 01 execute
- >>>>> 00 check for existence of file <<<<<
-
- This is simply a poor description. access() is a function that is portable
- across many platforms being derived from the Unix/POSIX definition (but isn't
- standard C). It can only check for the existence of a file where that file is
- accessible, it does not bypass filesystem permissions. Even under DOS/Windows
- this is an issue for network drives. access() if first and foremost a test
- for accessibility, only if that condition is met can it test for
- existence/readability/writability. Worse than that in its correct POSIX
- guise it may perform the test using different criteria than those
- applied to fopen(), open() etc. which is why in general you should avoid
- it and use something like stat() or fopen() directly.
-
- --
- -----------------------------------------
- Lawrence Kirby | fred@genesis.demon.co.uk
- Wilts, England | 70734.126@compuserve.com
- -----------------------------------------
-